class InsurersController < ApplicationController
  before_action :set_menu

  def index
    @submenu = :insurer_list
    @title = '保险公司'
    @insurers = Insurer.all
  end

  def new
    @insurer = Insurer.new
  end

  def create
    @insurer = Insurer.new post_params
    if @insurer.save
      redirect_to insurers_path
    else
      render :action => 'new'
    end
  end

  def edit
    @insurer = Insurer.find params[:id]
  end

  def update
    @insurer = Insurer.find params[:id]
    if @insurer.update_attributes post_params
      redirect_to insurers_path
    else
      render :action => 'edit'
    end
  end

  def destroy
    @insurer = Insurer.find params[:id]
    @insurer.destroy
    redirect_to insurers_path
  end


  def post_params
    params.require(:insurer).permit(*%w(name phone fax email note))
  end

  private
  def set_menu
    @mainmenu = :intercourse
  end
end
